<!--
 * @Description: 
 * @Author: jun.wu
 * @Date: 2022-10-26 16:58:28
 * @LastEditors: jun.wu
 * @LastEditTime: 2022-10-26 18:22:18
-->
<template>
  <upload-excel :on-success="success" />
</template>

<script>
import { importEmployee } from "@/api/employees";
export default {
  methods: {
    async success({ header, results }) {
      // header和results中的数据是中文,需要进行转化
      // 如果是导入员工
      const userRelations = {
        入职日期: "timeOfEntry",
        手机号: "mobile",
        姓名: "username",
        转正日期: "correctionTime",
        工号: "workNumber",
      };
      var arr = [];
      results.forEach((item) => {
        var userInfo = {};
        Object.keys(item).forEach((key) => {
          // key是中文
          userInfo[userRelations[key]] = item[key];
        });
        arr.push(userInfo);
      });
      //   var newArr = results.map((item) => {
      //     let userInfo = {};
      //     Object.keys(item).forEach((key) => {
      //       userInfo[userRelations[key]] = item[key];
      //     });
      //     return userInfo;
      //   });
      await importEmployee(arr);
      this.$message.success("导入数据成功");
      this.$router.back();
    },
  },
};
</script>

<style></style>
